package gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class ChulList extends JFrame {

	Chul[] chul;
	int pos;
	boolean flag;

	private JPanel contentPane;
	private JScrollPane scrollPane;
	private JTextArea textArea;

	/**
	 * Create the frame.
	 */
	public ChulList(Chul[] c, int pos, boolean b) {
		this.chul = c;
		this.pos = pos;
		this.flag = b;
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent arg0) {

			}
		});
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		contentPane.add(getScrollPane(), BorderLayout.CENTER);

		output();
	}

	public void output() {
		textArea.setText("");
		for (int i = pos - 1; i >= 0; i--) {
			String temp = (chul[i].checkIn != null) ? "출근" : "퇴근";
			textArea.append(chul[i].toString() + temp + "\n");
		}
		if (flag) { // 반복된 경우
			for (int i = chul.length - 1; i >= pos; i--) {
				String temp = (chul[i].checkIn != null) ? "출근" : "퇴근";
				textArea.append(chul[i].toString() + temp + "\n");
			}
		}

	}

	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setViewportView(getTextArea());
		}
		return scrollPane;
	}

	private JTextArea getTextArea() {
		if (textArea == null) {
			textArea = new JTextArea();
		}
		return textArea;
	}
}
